{
 "cells": [
  {
   "cell_type": "raw",
   "metadata": {},
   "source": [
    "## 第二章习题\n",
    "\n",
    "### 一、填空题\n",
    "\n",
    "1.列表的`sort()`方法没有返回值,或者说返回值为__None______."
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "2.已知列表 `data=[1,2,30 4]`，那么`data[2:100]`的值为________."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "[304]"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "3.己知`x=3`和`y=5`,那么执行语句`x,y=y,x`之后，`y`的值为________."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "3"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "4．已知字典 `data= {'a;97, 'A' :65}`,那么`data.get('a', None)`的值为________."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "97"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### 二、判断题\n",
    "\n",
    "1.生成器表达式的计算结果是一个元组。`(    )`"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "错"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "2．包含列表的元组可以作为字典的“键”。`(    )`"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "错"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "3．包含列表的元组不可以作为集合的元素。`(    )`"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "对"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "4．列表的`rindex()`方法返回指定元素在列表中最后一次出现的位置。`(    )`"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "错"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### 三、编程题\n",
    "\n",
    "1.输入一个字符串，输出其中每个字符的出现次数。要求使用标准库`collotections`中的`Counter`类,请自行查阅相关用法。"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "请输入一个字符串:'1,2,3,4,5,6'\n"
     ]
    }
   ],
   "source": [
    "s = eval(input('请输入一个字符串:'))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "1"
      ]
     },
     "execution_count": 14,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "s.count('1')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 15,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "1"
      ]
     },
     "execution_count": 15,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "s.count('2')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 16,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "1"
      ]
     },
     "execution_count": 16,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "s.count('3')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 17,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "1"
      ]
     },
     "execution_count": 17,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "s.count('4')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 18,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "1"
      ]
     },
     "execution_count": 18,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "s.count('5')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 19,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "1"
      ]
     },
     "execution_count": 19,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "s.count('6')"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "2．输入一个字符串,输出其中只出现了一次的字符及其下标。"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "请输入一个字符串:{'eye'}\n"
     ]
    }
   ],
   "source": [
    "text = input('请输入一个字符串:')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {},
   "outputs": [],
   "source": [
    "positions = [(ch, index) for index, ch in enumerate(text) if text.index(ch) == text.rindex(ch)]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[('{', 0), ('y', 3), ('}', 6)]\n"
     ]
    }
   ],
   "source": [
    "print(positions)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "3．输入一个字符串,输出其中每个唯一字符最后一次出现的下标。"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "4．输入包含若干集合的列表，输出这些集合的并集。提示:使用`reduce()`函数和`operator`模块中的运算实现多个集合的并集。"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {},
   "outputs": [],
   "source": [
    "from functools import reduce"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "请输入一个列表:[2, 3, 4]\n"
     ]
    }
   ],
   "source": [
    "lstA = eval(input(\"请输入一个列表:\"))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "7\n"
     ]
    }
   ],
   "source": [
    "print(reduce(lambda x, y: x | y, lstA))"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "5．输入一个字符串,检查该字符串是否为回文（正着读和反看读都一样的字符串)，如果是就输出`Yes`，否则输出`No`。要求使用切片实现"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 20,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "请输入一个字符串'1,2,3'\n"
     ]
    }
   ],
   "source": [
    "s = eval(input('请输入一个字符串'))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 21,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "No\n"
     ]
    }
   ],
   "source": [
    "x = s[::-1]\n",
    "if s == x:\n",
    "    print('Yes')\n",
    "else:\n",
    "    print('No')"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 课本上65页课后习题"
   ]
  },
  {
   "cell_type": "raw",
   "metadata": {},
   "source": [
    "1. Python 3.x的range()函数返回一个_range可迭代对象"
   ]
  },
  {
   "cell_type": "raw",
   "metadata": {},
   "source": [
    "2.表达式“[3]in [1,2,3,4]”的值为4"
   ]
  },
  {
   "cell_type": "raw",
   "metadata": {},
   "source": [
    "3.列表对象的 sort()方法用来对列表元素进行原地排序,该函数返回值"
   ]
  },
  {
   "cell_type": "raw",
   "metadata": {},
   "source": [
    "4.列表对象的remove方法删除首次出现的指定元素,如果列表中不存在要删除的元素，则抛出异常。"
   ]
  },
  {
   "cell_type": "raw",
   "metadata": {},
   "source": [
    "5.假设列表对象aList的值为[3,4,5,6,7,9,11,13,15,17],那么切片aList[3:7]得的值是6，7,9，11]"
   ]
  },
  {
   "cell_type": "raw",
   "metadata": {},
   "source": [
    "6.在 Python 中,字典和集合都是用一对[]作为界定符,字典的每个元素由两部分组成，即键_和值,其中键不允许重复。"
   ]
  },
  {
   "cell_type": "raw",
   "metadata": {},
   "source": [
    "7.使用字典对象的 items(方法可以返回字典的“键:值”对，使用字典对象的 keys()方法可以返回字典的“键”,使用字典对象的 valuex方法可以返回字典的“值”。"
   ]
  },
  {
   "cell_type": "raw",
   "metadata": {},
   "source": [
    "8.假设有列表 a=['name','age', 'sex']和 b=['Dong',38,'Male'],使用一条语句将这两个列表的内容转换为字典,并且以列表a中的元素为“键”,以列表b中的元素为“值”,这个语句可以写为c=dict(zipla,b))"
   ]
  },
  {
   "cell_type": "raw",
   "metadata": {},
   "source": [
    "9.假设有一个列表a,现要求从列表a中每3个元素取1个，并且将取到的元素组成新的列表b,可以使用语句b=a[::3]"
   ]
  },
  {
   "cell_type": "raw",
   "metadata": {},
   "source": [
    "10.使用列表推导式生成包含10个数字5的列表,语句可以写为[5 for i in range(10)]"
   ]
  },
  {
   "cell_type": "raw",
   "metadata": {},
   "source": [
    "11. 不可以(可以、不可以)使用del命令来删除元组中的部分元素。"
   ]
  },
  {
   "cell_type": "raw",
   "metadata": {},
   "source": [
    "12.已知列表data中有若干字符串,要求编写程序,对data中的字符串进行过滤，只输出重复字符不超过一半的字符串。"
   ]
  },
  {
   "cell_type": "raw",
   "metadata": {},
   "source": [
    "13.编写程序,使用筛选法查找并输出小于1000的所有素数。"
   ]
  },
  {
   "cell_type": "raw",
   "metadata": {},
   "source": [
    "14.为什么应尽量从列表的尾部进行元素的增加与删除操作?提高运作速度"
   ]
  },
  {
   "cell_type": "raw",
   "metadata": {},
   "source": [
    "15.编写程序,生成包含1000个0~100的随机整数,并统计每个元素的出现次数。"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 25,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[61, 63, 65, 22, 17, 83, 74, 48, 88, 63, 96, 29, 13, 17, 57, 80, 61, 10, 78, 72, 5, 39, 26, 30, 23, 72, 1, 21, 64, 43, 26, 3, 11, 79, 48, 0, 34, 70, 30, 83, 6, 78, 3, 7, 17, 1, 95, 70, 74, 100, 54, 57, 25, 43, 98, 97, 27, 84, 30, 0, 24, 30, 3, 59, 66, 83, 42, 90, 37, 53, 38, 73, 99, 23, 10, 79, 67, 49, 57, 57, 20, 32, 54, 21, 9, 49, 79, 87, 77, 53, 82, 80, 0, 76, 98, 71, 21, 68, 83, 7, 56, 1, 14, 13, 91, 57, 25, 2, 98, 53, 75, 19, 73, 73, 30, 42, 55, 26, 79, 98, 94, 55, 56, 96, 85, 90, 66, 5, 43, 90, 49, 71, 24, 11, 15, 7, 52, 71, 90, 50, 66, 74, 54, 49, 64, 13, 63, 82, 48, 87, 67, 8, 63, 44, 58, 87, 44, 91, 93, 98, 47, 24, 80, 96, 92, 14, 22, 21, 62, 50, 79, 77, 50, 62, 59, 53, 28, 65, 45, 90, 85, 59, 90, 93, 46, 5, 75, 59, 5, 79, 89, 59, 89, 13, 78, 20, 61, 60, 75, 78, 43, 10, 31, 32, 19, 7, 12, 26, 0, 49, 1, 6, 15, 70, 83, 22, 23, 68, 16, 17, 63, 46, 55, 9, 24, 93, 38, 31, 20, 50, 54, 99, 81, 54, 90, 52, 63, 92, 77, 41, 90, 9, 85, 15, 56, 62, 32, 70, 8, 68, 4, 96, 86, 3, 8, 97, 48, 91, 48, 61, 17, 52, 59, 41, 43, 85, 13, 42, 28, 93, 5, 63, 67, 33, 32, 31, 50, 32, 71, 17, 79, 5, 55, 55, 89, 47, 63, 5, 1, 65, 55, 17, 26, 22, 76, 72, 32, 71, 97, 10, 51, 72, 94, 34, 52, 29, 21, 83, 34, 75, 53, 14, 37, 48, 54, 53, 90, 42, 71, 7, 51, 67, 25, 71, 73, 42, 6, 75, 95, 4, 1, 77, 95, 15, 47, 39, 16, 99, 69, 40, 41, 85, 8, 13, 0, 13, 63, 18, 95, 63, 9, 88, 82, 5, 71, 89, 98, 21, 30, 45, 55, 8, 52, 25, 71, 77, 24, 74, 91, 15, 42, 53, 15, 25, 10, 88, 76, 1, 10, 62, 34, 42, 5, 51, 16, 13, 95, 49, 44, 6, 98, 76, 11, 22, 17, 24, 49, 18, 23, 56, 44, 71, 27, 45, 55, 45, 91, 80, 71, 44, 47, 92, 77, 92, 8, 51, 63, 45, 89, 99, 56, 49, 6, 58, 1, 88, 59, 33, 22, 77, 7, 91, 89, 95, 51, 85, 99, 25, 89, 11, 89, 87, 33, 86, 42, 73, 47, 50, 55, 75, 91, 97, 23, 28, 84, 88, 87, 93, 66, 49, 27, 19, 52, 61, 61, 82, 65, 17, 90, 21, 48, 26, 89, 96, 5, 61, 50, 87, 70, 16, 67, 28, 50, 25, 0, 46, 99, 90, 69, 39, 100, 9, 76, 7, 75, 97, 39, 1, 92, 30, 79, 55, 44, 50, 28, 9, 18, 74, 12, 28, 67, 70, 69, 95, 67, 19, 100, 24, 89, 22, 87, 0, 92, 70, 63, 89, 51, 37, 39, 19, 34, 46, 84, 77, 36, 11, 54, 36, 66, 56, 39, 93, 22, 91, 4, 0, 41, 37, 38, 24, 32, 61, 2, 7, 83, 97, 48, 1, 31, 92, 68, 65, 17, 13, 27, 73, 32, 65, 52, 2, 84, 93, 87, 49, 18, 55, 39, 54, 8, 47, 28, 43, 62, 46, 77, 30, 11, 51, 4, 55, 43, 87, 59, 13, 72, 88, 31, 67, 30, 18, 49, 10, 95, 3, 31, 77, 48, 58, 66, 57, 80, 73, 93, 44, 8, 88, 55, 33, 30, 90, 99, 45, 18, 99, 16, 77, 66, 47, 8, 17, 23, 15, 28, 3, 4, 1, 32, 70, 90, 64, 98, 21, 68, 65, 57, 7, 1, 46, 93, 93, 46, 93, 46, 38, 9, 53, 32, 62, 73, 46, 43, 61, 12, 4, 7, 5, 57, 96, 94, 14, 13, 36, 89, 98, 83, 38, 57, 27, 12, 64, 52, 28, 57, 61, 36, 46, 99, 100, 41, 65, 85, 16, 26, 77, 1, 35, 60, 29, 39, 59, 4, 12, 88, 14, 95, 30, 51, 58, 38, 56, 29, 79, 12, 63, 97, 3, 32, 9, 56, 98, 81, 94, 80, 84, 31, 50, 16, 56, 31, 14, 41, 61, 64, 90, 67, 51, 61, 31, 84, 33, 24, 75, 73, 38, 15, 93, 86, 41, 60, 13, 66, 96, 97, 97, 29, 26, 84, 46, 1, 61, 29, 39, 49, 18, 65, 27, 53, 15, 58, 41, 49, 6, 24, 68, 6, 40, 62, 23, 16, 30, 30, 69, 0, 50, 59, 89, 51, 63, 96, 26, 18, 8, 12, 90, 56, 64, 20, 66, 59, 30, 1, 100, 52, 33, 42, 76, 70, 96, 100, 32, 64, 98, 79, 85, 91, 71, 3, 88, 61, 35, 54, 11, 74, 62, 46, 14, 88, 28, 78, 91, 98, 16, 73, 96, 100, 30, 86, 61, 30, 81, 2, 67, 81, 31, 19, 59, 79, 36, 67, 21, 76, 64, 2, 55, 0, 50, 7, 8, 16, 22, 29, 24, 21, 30, 83, 53, 5, 12, 86, 95, 24, 33, 55, 67, 10, 21, 50, 34, 65, 86, 79, 54, 53, 37, 99, 49, 98, 22, 97, 90, 15, 86, 57, 12, 79, 83, 46, 27, 50, 76, 85, 43, 32, 26, 66, 9, 26, 90, 61, 62, 70, 0, 67, 12, 57, 58, 34, 50, 43, 45, 21, 53, 28, 100, 43, 90, 33, 35, 31, 48, 63, 24, 97, 2, 92, 43, 13, 40, 15, 51, 19, 27, 36, 15, 94, 23, 45, 81, 80, 73, 39, 20, 80, 71, 11, 67, 79, 46, 8, 68, 20, 77, 22, 56, 93, 59, 51, 79, 26, 33, 23, 71, 46, 17, 34, 10, 93, 87, 43, 26, 51, 94, 9, 39, 49, 9, 50, 32, 9, 73, 14, 9, 36, 21, 89, 17, 68, 62, 11, 70]\n",
      "61 : 16\n",
      "63 : 15\n",
      "65 : 10\n",
      "22 : 11\n",
      "17 : 13\n",
      "83 : 10\n",
      "74 : 6\n",
      "48 : 10\n",
      "88 : 10\n",
      "63 : 15\n",
      "96 : 10\n",
      "29 : 7\n",
      "13 : 13\n",
      "17 : 13\n",
      "57 : 12\n",
      "80 : 8\n",
      "61 : 16\n",
      "10 : 9\n",
      "78 : 5\n",
      "72 : 5\n",
      "5 : 12\n",
      "39 : 11\n",
      "26 : 13\n",
      "30 : 17\n",
      "23 : 9\n",
      "72 : 5\n",
      "1 : 15\n",
      "21 : 13\n",
      "64 : 8\n",
      "43 : 13\n",
      "26 : 13\n",
      "3 : 8\n",
      "11 : 9\n",
      "79 : 15\n",
      "48 : 10\n",
      "0 : 11\n",
      "34 : 8\n",
      "70 : 11\n",
      "30 : 17\n",
      "83 : 10\n",
      "6 : 7\n",
      "78 : 5\n",
      "3 : 8\n",
      "7 : 11\n",
      "17 : 13\n",
      "1 : 15\n",
      "95 : 10\n",
      "70 : 11\n",
      "74 : 6\n",
      "100 : 8\n",
      "54 : 10\n",
      "57 : 12\n",
      "25 : 7\n",
      "43 : 13\n",
      "98 : 13\n",
      "97 : 11\n",
      "27 : 8\n",
      "84 : 7\n",
      "30 : 17\n",
      "0 : 11\n",
      "24 : 13\n",
      "30 : 17\n",
      "3 : 8\n",
      "59 : 13\n",
      "66 : 10\n",
      "83 : 10\n",
      "42 : 9\n",
      "90 : 18\n",
      "37 : 5\n",
      "53 : 12\n",
      "38 : 7\n",
      "73 : 12\n",
      "99 : 10\n",
      "23 : 9\n",
      "10 : 9\n",
      "79 : 15\n",
      "67 : 14\n",
      "49 : 15\n",
      "57 : 12\n",
      "57 : 12\n",
      "20 : 6\n",
      "32 : 14\n",
      "54 : 10\n",
      "21 : 13\n",
      "9 : 13\n",
      "49 : 15\n",
      "79 : 15\n",
      "87 : 10\n",
      "77 : 13\n",
      "53 : 12\n",
      "82 : 4\n",
      "80 : 8\n",
      "0 : 11\n",
      "76 : 8\n",
      "98 : 13\n",
      "71 : 14\n",
      "21 : 13\n",
      "68 : 8\n",
      "83 : 10\n",
      "7 : 11\n",
      "56 : 11\n",
      "1 : 15\n",
      "14 : 8\n",
      "13 : 13\n",
      "91 : 10\n",
      "57 : 12\n",
      "25 : 7\n",
      "2 : 6\n",
      "98 : 13\n",
      "53 : 12\n",
      "75 : 8\n",
      "19 : 7\n",
      "73 : 12\n",
      "73 : 12\n",
      "30 : 17\n",
      "42 : 9\n",
      "55 : 15\n",
      "26 : 13\n",
      "79 : 15\n",
      "98 : 13\n",
      "94 : 6\n",
      "55 : 15\n",
      "56 : 11\n",
      "96 : 10\n",
      "85 : 9\n",
      "90 : 18\n",
      "66 : 10\n",
      "5 : 12\n",
      "43 : 13\n",
      "90 : 18\n",
      "49 : 15\n",
      "71 : 14\n",
      "24 : 13\n",
      "11 : 9\n",
      "15 : 12\n",
      "7 : 11\n",
      "52 : 9\n",
      "71 : 14\n",
      "90 : 18\n",
      "50 : 16\n",
      "66 : 10\n",
      "74 : 6\n",
      "54 : 10\n",
      "49 : 15\n",
      "64 : 8\n",
      "13 : 13\n",
      "63 : 15\n",
      "82 : 4\n",
      "48 : 10\n",
      "87 : 10\n",
      "67 : 14\n",
      "8 : 12\n",
      "63 : 15\n",
      "44 : 7\n",
      "58 : 6\n",
      "87 : 10\n",
      "44 : 7\n",
      "91 : 10\n",
      "93 : 14\n",
      "98 : 13\n",
      "47 : 7\n",
      "24 : 13\n",
      "80 : 8\n",
      "96 : 10\n",
      "92 : 8\n",
      "14 : 8\n",
      "22 : 11\n",
      "21 : 13\n",
      "62 : 10\n",
      "50 : 16\n",
      "79 : 15\n",
      "77 : 13\n",
      "50 : 16\n",
      "62 : 10\n",
      "59 : 13\n",
      "53 : 12\n",
      "28 : 11\n",
      "65 : 10\n",
      "45 : 8\n",
      "90 : 18\n",
      "85 : 9\n",
      "59 : 13\n",
      "90 : 18\n",
      "93 : 14\n",
      "46 : 15\n",
      "5 : 12\n",
      "75 : 8\n",
      "59 : 13\n",
      "5 : 12\n",
      "79 : 15\n",
      "89 : 14\n",
      "59 : 13\n",
      "89 : 14\n",
      "13 : 13\n",
      "78 : 5\n",
      "20 : 6\n",
      "61 : 16\n",
      "60 : 3\n",
      "75 : 8\n",
      "78 : 5\n",
      "43 : 13\n",
      "10 : 9\n",
      "31 : 11\n",
      "32 : 14\n",
      "19 : 7\n",
      "7 : 11\n",
      "12 : 10\n",
      "26 : 13\n",
      "0 : 11\n",
      "49 : 15\n",
      "1 : 15\n",
      "6 : 7\n",
      "15 : 12\n",
      "70 : 11\n",
      "83 : 10\n",
      "22 : 11\n",
      "23 : 9\n",
      "68 : 8\n",
      "16 : 10\n",
      "17 : 13\n",
      "63 : 15\n",
      "46 : 15\n",
      "55 : 15\n",
      "9 : 13\n",
      "24 : 13\n",
      "93 : 14\n",
      "38 : 7\n",
      "31 : 11\n",
      "20 : 6\n",
      "50 : 16\n",
      "54 : 10\n",
      "99 : 10\n",
      "81 : 5\n",
      "54 : 10\n",
      "90 : 18\n",
      "52 : 9\n",
      "63 : 15\n",
      "92 : 8\n",
      "77 : 13\n",
      "41 : 8\n",
      "90 : 18\n",
      "9 : 13\n",
      "85 : 9\n",
      "15 : 12\n",
      "56 : 11\n",
      "62 : 10\n",
      "32 : 14\n",
      "70 : 11\n",
      "8 : 12\n",
      "68 : 8\n",
      "4 : 7\n",
      "96 : 10\n",
      "86 : 7\n",
      "3 : 8\n",
      "8 : 12\n",
      "97 : 11\n",
      "48 : 10\n",
      "91 : 10\n",
      "48 : 10\n",
      "61 : 16\n",
      "17 : 13\n",
      "52 : 9\n",
      "59 : 13\n",
      "41 : 8\n",
      "43 : 13\n",
      "85 : 9\n",
      "13 : 13\n",
      "42 : 9\n",
      "28 : 11\n",
      "93 : 14\n",
      "5 : 12\n",
      "63 : 15\n",
      "67 : 14\n",
      "33 : 9\n",
      "32 : 14\n",
      "31 : 11\n",
      "50 : 16\n",
      "32 : 14\n",
      "71 : 14\n",
      "17 : 13\n",
      "79 : 15\n",
      "5 : 12\n",
      "55 : 15\n",
      "55 : 15\n",
      "89 : 14\n",
      "47 : 7\n",
      "63 : 15\n",
      "5 : 12\n",
      "1 : 15\n",
      "65 : 10\n",
      "55 : 15\n",
      "17 : 13\n",
      "26 : 13\n",
      "22 : 11\n",
      "76 : 8\n",
      "72 : 5\n",
      "32 : 14\n",
      "71 : 14\n",
      "97 : 11\n",
      "10 : 9\n",
      "51 : 13\n",
      "72 : 5\n",
      "94 : 6\n",
      "34 : 8\n",
      "52 : 9\n",
      "29 : 7\n",
      "21 : 13\n",
      "83 : 10\n",
      "34 : 8\n",
      "75 : 8\n",
      "53 : 12\n",
      "14 : 8\n",
      "37 : 5\n",
      "48 : 10\n",
      "54 : 10\n",
      "53 : 12\n",
      "90 : 18\n",
      "42 : 9\n",
      "71 : 14\n",
      "7 : 11\n",
      "51 : 13\n",
      "67 : 14\n",
      "25 : 7\n",
      "71 : 14\n",
      "73 : 12\n",
      "42 : 9\n",
      "6 : 7\n",
      "75 : 8\n",
      "95 : 10\n",
      "4 : 7\n",
      "1 : 15\n",
      "77 : 13\n",
      "95 : 10\n",
      "15 : 12\n",
      "47 : 7\n",
      "39 : 11\n",
      "16 : 10\n",
      "99 : 10\n",
      "69 : 4\n",
      "40 : 3\n",
      "41 : 8\n",
      "85 : 9\n",
      "8 : 12\n",
      "13 : 13\n",
      "0 : 11\n",
      "13 : 13\n",
      "63 : 15\n",
      "18 : 8\n",
      "95 : 10\n",
      "63 : 15\n",
      "9 : 13\n",
      "88 : 10\n",
      "82 : 4\n",
      "5 : 12\n",
      "71 : 14\n",
      "89 : 14\n",
      "98 : 13\n",
      "21 : 13\n",
      "30 : 17\n",
      "45 : 8\n",
      "55 : 15\n",
      "8 : 12\n",
      "52 : 9\n",
      "25 : 7\n",
      "71 : 14\n",
      "77 : 13\n",
      "24 : 13\n",
      "74 : 6\n",
      "91 : 10\n",
      "15 : 12\n",
      "42 : 9\n",
      "53 : 12\n",
      "15 : 12\n",
      "25 : 7\n",
      "10 : 9\n",
      "88 : 10\n",
      "76 : 8\n",
      "1 : 15\n",
      "10 : 9\n",
      "62 : 10\n",
      "34 : 8\n",
      "42 : 9\n",
      "5 : 12\n",
      "51 : 13\n",
      "16 : 10\n",
      "13 : 13\n",
      "95 : 10\n",
      "49 : 15\n",
      "44 : 7\n",
      "6 : 7\n",
      "98 : 13\n",
      "76 : 8\n",
      "11 : 9\n",
      "22 : 11\n",
      "17 : 13\n",
      "24 : 13\n",
      "49 : 15\n",
      "18 : 8\n",
      "23 : 9\n",
      "56 : 11\n",
      "44 : 7\n",
      "71 : 14\n",
      "27 : 8\n",
      "45 : 8\n",
      "55 : 15\n",
      "45 : 8\n",
      "91 : 10\n",
      "80 : 8\n",
      "71 : 14\n",
      "44 : 7\n",
      "47 : 7\n",
      "92 : 8\n",
      "77 : 13\n",
      "92 : 8\n",
      "8 : 12\n",
      "51 : 13\n",
      "63 : 15\n",
      "45 : 8\n",
      "89 : 14\n",
      "99 : 10\n",
      "56 : 11\n",
      "49 : 15\n",
      "6 : 7\n",
      "58 : 6\n",
      "1 : 15\n",
      "88 : 10\n",
      "59 : 13\n",
      "33 : 9\n",
      "22 : 11\n",
      "77 : 13\n",
      "7 : 11\n",
      "91 : 10\n",
      "89 : 14\n",
      "95 : 10\n",
      "51 : 13\n",
      "85 : 9\n",
      "99 : 10\n",
      "25 : 7\n",
      "89 : 14\n",
      "11 : 9\n",
      "89 : 14\n",
      "87 : 10\n",
      "33 : 9\n",
      "86 : 7\n",
      "42 : 9\n",
      "73 : 12\n",
      "47 : 7\n",
      "50 : 16\n",
      "55 : 15\n",
      "75 : 8\n",
      "91 : 10\n",
      "97 : 11\n",
      "23 : 9\n",
      "28 : 11\n",
      "84 : 7\n",
      "88 : 10\n",
      "87 : 10\n",
      "93 : 14\n",
      "66 : 10\n",
      "49 : 15\n",
      "27 : 8\n",
      "19 : 7\n",
      "52 : 9\n",
      "61 : 16\n",
      "61 : 16\n",
      "82 : 4\n",
      "65 : 10\n",
      "17 : 13\n",
      "90 : 18\n",
      "21 : 13\n",
      "48 : 10\n",
      "26 : 13\n",
      "89 : 14\n",
      "96 : 10\n",
      "5 : 12\n",
      "61 : 16\n",
      "50 : 16\n",
      "87 : 10\n",
      "70 : 11\n",
      "16 : 10\n",
      "67 : 14\n",
      "28 : 11\n",
      "50 : 16\n",
      "25 : 7\n",
      "0 : 11\n",
      "46 : 15\n",
      "99 : 10\n",
      "90 : 18\n",
      "69 : 4\n",
      "39 : 11\n",
      "100 : 8\n",
      "9 : 13\n",
      "76 : 8\n",
      "7 : 11\n",
      "75 : 8\n",
      "97 : 11\n",
      "39 : 11\n",
      "1 : 15\n",
      "92 : 8\n",
      "30 : 17\n",
      "79 : 15\n",
      "55 : 15\n",
      "44 : 7\n",
      "50 : 16\n",
      "28 : 11\n",
      "9 : 13\n",
      "18 : 8\n",
      "74 : 6\n",
      "12 : 10\n",
      "28 : 11\n",
      "67 : 14\n",
      "70 : 11\n",
      "69 : 4\n",
      "95 : 10\n",
      "67 : 14\n",
      "19 : 7\n",
      "100 : 8\n",
      "24 : 13\n",
      "89 : 14\n",
      "22 : 11\n",
      "87 : 10\n",
      "0 : 11\n",
      "92 : 8\n",
      "70 : 11\n",
      "63 : 15\n",
      "89 : 14\n",
      "51 : 13\n",
      "37 : 5\n",
      "39 : 11\n",
      "19 : 7\n",
      "34 : 8\n",
      "46 : 15\n",
      "84 : 7\n",
      "77 : 13\n",
      "36 : 7\n",
      "11 : 9\n",
      "54 : 10\n",
      "36 : 7\n",
      "66 : 10\n",
      "56 : 11\n",
      "39 : 11\n",
      "93 : 14\n",
      "22 : 11\n",
      "91 : 10\n",
      "4 : 7\n",
      "0 : 11\n",
      "41 : 8\n",
      "37 : 5\n",
      "38 : 7\n",
      "24 : 13\n",
      "32 : 14\n",
      "61 : 16\n",
      "2 : 6\n",
      "7 : 11\n",
      "83 : 10\n",
      "97 : 11\n",
      "48 : 10\n",
      "1 : 15\n",
      "31 : 11\n",
      "92 : 8\n",
      "68 : 8\n",
      "65 : 10\n",
      "17 : 13\n",
      "13 : 13\n",
      "27 : 8\n",
      "73 : 12\n",
      "32 : 14\n",
      "65 : 10\n",
      "52 : 9\n",
      "2 : 6\n",
      "84 : 7\n",
      "93 : 14\n",
      "87 : 10\n",
      "49 : 15\n",
      "18 : 8\n",
      "55 : 15\n",
      "39 : 11\n",
      "54 : 10\n",
      "8 : 12\n",
      "47 : 7\n",
      "28 : 11\n",
      "43 : 13\n",
      "62 : 10\n",
      "46 : 15\n",
      "77 : 13\n",
      "30 : 17\n",
      "11 : 9\n",
      "51 : 13\n",
      "4 : 7\n",
      "55 : 15\n",
      "43 : 13\n",
      "87 : 10\n",
      "59 : 13\n",
      "13 : 13\n",
      "72 : 5\n",
      "88 : 10\n",
      "31 : 11\n",
      "67 : 14\n",
      "30 : 17\n",
      "18 : 8\n",
      "49 : 15\n",
      "10 : 9\n",
      "95 : 10\n",
      "3 : 8\n",
      "31 : 11\n",
      "77 : 13\n",
      "48 : 10\n",
      "58 : 6\n",
      "66 : 10\n",
      "57 : 12\n",
      "80 : 8\n",
      "73 : 12\n",
      "93 : 14\n",
      "44 : 7\n",
      "8 : 12\n",
      "88 : 10\n",
      "55 : 15\n",
      "33 : 9\n",
      "30 : 17\n",
      "90 : 18\n",
      "99 : 10\n",
      "45 : 8\n",
      "18 : 8\n",
      "99 : 10\n",
      "16 : 10\n",
      "77 : 13\n",
      "66 : 10\n",
      "47 : 7\n",
      "8 : 12\n",
      "17 : 13\n",
      "23 : 9\n",
      "15 : 12\n",
      "28 : 11\n",
      "3 : 8\n",
      "4 : 7\n",
      "1 : 15\n",
      "32 : 14\n",
      "70 : 11\n",
      "90 : 18\n",
      "64 : 8\n",
      "98 : 13\n",
      "21 : 13\n",
      "68 : 8\n",
      "65 : 10\n",
      "57 : 12\n",
      "7 : 11\n",
      "1 : 15\n",
      "46 : 15\n",
      "93 : 14\n",
      "93 : 14\n",
      "46 : 15\n",
      "93 : 14\n",
      "46 : 15\n",
      "38 : 7\n",
      "9 : 13\n",
      "53 : 12\n",
      "32 : 14\n",
      "62 : 10\n",
      "73 : 12\n",
      "46 : 15\n",
      "43 : 13\n",
      "61 : 16\n",
      "12 : 10\n",
      "4 : 7\n",
      "7 : 11\n",
      "5 : 12\n",
      "57 : 12\n",
      "96 : 10\n",
      "94 : 6\n",
      "14 : 8\n",
      "13 : 13\n",
      "36 : 7\n",
      "89 : 14\n",
      "98 : 13\n",
      "83 : 10\n",
      "38 : 7\n",
      "57 : 12\n",
      "27 : 8\n",
      "12 : 10\n",
      "64 : 8\n",
      "52 : 9\n",
      "28 : 11\n",
      "57 : 12\n",
      "61 : 16\n",
      "36 : 7\n",
      "46 : 15\n",
      "99 : 10\n",
      "100 : 8\n",
      "41 : 8\n",
      "65 : 10\n",
      "85 : 9\n",
      "16 : 10\n",
      "26 : 13\n",
      "77 : 13\n",
      "1 : 15\n",
      "35 : 3\n",
      "60 : 3\n",
      "29 : 7\n",
      "39 : 11\n",
      "59 : 13\n",
      "4 : 7\n",
      "12 : 10\n",
      "88 : 10\n",
      "14 : 8\n",
      "95 : 10\n",
      "30 : 17\n",
      "51 : 13\n",
      "58 : 6\n",
      "38 : 7\n",
      "56 : 11\n",
      "29 : 7\n",
      "79 : 15\n",
      "12 : 10\n",
      "63 : 15\n",
      "97 : 11\n",
      "3 : 8\n",
      "32 : 14\n",
      "9 : 13\n",
      "56 : 11\n",
      "98 : 13\n",
      "81 : 5\n",
      "94 : 6\n",
      "80 : 8\n",
      "84 : 7\n",
      "31 : 11\n",
      "50 : 16\n",
      "16 : 10\n",
      "56 : 11\n",
      "31 : 11\n",
      "14 : 8\n",
      "41 : 8\n",
      "61 : 16\n",
      "64 : 8\n",
      "90 : 18\n",
      "67 : 14\n",
      "51 : 13\n",
      "61 : 16\n",
      "31 : 11\n",
      "84 : 7\n",
      "33 : 9\n",
      "24 : 13\n",
      "75 : 8\n",
      "73 : 12\n",
      "38 : 7\n",
      "15 : 12\n",
      "93 : 14\n",
      "86 : 7\n",
      "41 : 8\n",
      "60 : 3\n",
      "13 : 13\n",
      "66 : 10\n",
      "96 : 10\n",
      "97 : 11\n",
      "97 : 11\n",
      "29 : 7\n",
      "26 : 13\n",
      "84 : 7\n",
      "46 : 15\n",
      "1 : 15\n",
      "61 : 16\n",
      "29 : 7\n",
      "39 : 11\n",
      "49 : 15\n",
      "18 : 8\n",
      "65 : 10\n",
      "27 : 8\n",
      "53 : 12\n",
      "15 : 12\n",
      "58 : 6\n",
      "41 : 8\n",
      "49 : 15\n",
      "6 : 7\n",
      "24 : 13\n",
      "68 : 8\n",
      "6 : 7\n",
      "40 : 3\n",
      "62 : 10\n",
      "23 : 9\n",
      "16 : 10\n",
      "30 : 17\n",
      "30 : 17\n",
      "69 : 4\n",
      "0 : 11\n",
      "50 : 16\n",
      "59 : 13\n",
      "89 : 14\n",
      "51 : 13\n",
      "63 : 15\n",
      "96 : 10\n",
      "26 : 13\n",
      "18 : 8\n",
      "8 : 12\n",
      "12 : 10\n",
      "90 : 18\n",
      "56 : 11\n",
      "64 : 8\n",
      "20 : 6\n",
      "66 : 10\n",
      "59 : 13\n",
      "30 : 17\n",
      "1 : 15\n",
      "100 : 8\n",
      "52 : 9\n",
      "33 : 9\n",
      "42 : 9\n",
      "76 : 8\n",
      "70 : 11\n",
      "96 : 10\n",
      "100 : 8\n",
      "32 : 14\n",
      "64 : 8\n",
      "98 : 13\n",
      "79 : 15\n",
      "85 : 9\n",
      "91 : 10\n",
      "71 : 14\n",
      "3 : 8\n",
      "88 : 10\n",
      "61 : 16\n",
      "35 : 3\n",
      "54 : 10\n",
      "11 : 9\n",
      "74 : 6\n",
      "62 : 10\n",
      "46 : 15\n",
      "14 : 8\n",
      "88 : 10\n",
      "28 : 11\n",
      "78 : 5\n",
      "91 : 10\n",
      "98 : 13\n",
      "16 : 10\n",
      "73 : 12\n",
      "96 : 10\n",
      "100 : 8\n",
      "30 : 17\n",
      "86 : 7\n",
      "61 : 16\n",
      "30 : 17\n",
      "81 : 5\n",
      "2 : 6\n",
      "67 : 14\n",
      "81 : 5\n",
      "31 : 11\n",
      "19 : 7\n",
      "59 : 13\n",
      "79 : 15\n",
      "36 : 7\n",
      "67 : 14\n",
      "21 : 13\n",
      "76 : 8\n",
      "64 : 8\n",
      "2 : 6\n",
      "55 : 15\n",
      "0 : 11\n",
      "50 : 16\n",
      "7 : 11\n",
      "8 : 12\n",
      "16 : 10\n",
      "22 : 11\n",
      "29 : 7\n",
      "24 : 13\n",
      "21 : 13\n",
      "30 : 17\n",
      "83 : 10\n",
      "53 : 12\n",
      "5 : 12\n",
      "12 : 10\n",
      "86 : 7\n",
      "95 : 10\n",
      "24 : 13\n",
      "33 : 9\n",
      "55 : 15\n",
      "67 : 14\n",
      "10 : 9\n",
      "21 : 13\n",
      "50 : 16\n",
      "34 : 8\n",
      "65 : 10\n",
      "86 : 7\n",
      "79 : 15\n",
      "54 : 10\n",
      "53 : 12\n",
      "37 : 5\n",
      "99 : 10\n",
      "49 : 15\n",
      "98 : 13\n",
      "22 : 11\n",
      "97 : 11\n",
      "90 : 18\n",
      "15 : 12\n",
      "86 : 7\n",
      "57 : 12\n",
      "12 : 10\n",
      "79 : 15\n",
      "83 : 10\n",
      "46 : 15\n",
      "27 : 8\n",
      "50 : 16\n",
      "76 : 8\n",
      "85 : 9\n",
      "43 : 13\n",
      "32 : 14\n",
      "26 : 13\n",
      "66 : 10\n",
      "9 : 13\n",
      "26 : 13\n",
      "90 : 18\n",
      "61 : 16\n",
      "62 : 10\n",
      "70 : 11\n",
      "0 : 11\n",
      "67 : 14\n",
      "12 : 10\n",
      "57 : 12\n",
      "58 : 6\n",
      "34 : 8\n",
      "50 : 16\n",
      "43 : 13\n",
      "45 : 8\n",
      "21 : 13\n",
      "53 : 12\n",
      "28 : 11\n",
      "100 : 8\n",
      "43 : 13\n",
      "90 : 18\n",
      "33 : 9\n",
      "35 : 3\n",
      "31 : 11\n",
      "48 : 10\n",
      "63 : 15\n",
      "24 : 13\n",
      "97 : 11\n",
      "2 : 6\n",
      "92 : 8\n",
      "43 : 13\n",
      "13 : 13\n",
      "40 : 3\n",
      "15 : 12\n",
      "51 : 13\n",
      "19 : 7\n",
      "27 : 8\n",
      "36 : 7\n",
      "15 : 12\n",
      "94 : 6\n",
      "23 : 9\n",
      "45 : 8\n",
      "81 : 5\n",
      "80 : 8\n",
      "73 : 12\n",
      "39 : 11\n",
      "20 : 6\n",
      "80 : 8\n",
      "71 : 14\n",
      "11 : 9\n",
      "67 : 14\n",
      "79 : 15\n",
      "46 : 15\n",
      "8 : 12\n",
      "68 : 8\n",
      "20 : 6\n",
      "77 : 13\n",
      "22 : 11\n",
      "56 : 11\n",
      "93 : 14\n",
      "59 : 13\n",
      "51 : 13\n",
      "79 : 15\n",
      "26 : 13\n",
      "33 : 9\n",
      "23 : 9\n",
      "71 : 14\n",
      "46 : 15\n",
      "17 : 13\n",
      "34 : 8\n",
      "10 : 9\n",
      "93 : 14\n",
      "87 : 10\n",
      "43 : 13\n",
      "26 : 13\n",
      "51 : 13\n",
      "94 : 6\n",
      "9 : 13\n",
      "39 : 11\n",
      "49 : 15\n",
      "9 : 13\n",
      "50 : 16\n",
      "32 : 14\n",
      "9 : 13\n",
      "73 : 12\n",
      "14 : 8\n",
      "9 : 13\n",
      "36 : 7\n",
      "21 : 13\n",
      "89 : 14\n",
      "17 : 13\n",
      "68 : 8\n",
      "62 : 10\n",
      "11 : 9\n",
      "70 : 11\n"
     ]
    }
   ],
   "source": [
    "import random\n",
    "x = [random.randint(0,100)for i in range(1000)]\n",
    "print(x)\n",
    "for i in x:\n",
    "    print(i,':',x.count(i))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 22,
   "metadata": {},
   "outputs": [],
   "source": [
    "import random"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "x=[random.choice(range(101)) for i in range(1000)]\n",
    "y=set(x)"
   ]
  },
  {
   "cell_type": "raw",
   "metadata": {},
   "source": [
    "16.编写程序,用户输入一个列表和2个整数作为下标,然后输出列表中介于2个下标闭区间之间的元素组成的子列表。例如用户输入[1,2,3,4,5,6]和2,5,程序输出[3,45,6]。"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "18.编写程序,生成包含20个随机数的列表,然后将前10个元素升序排列,后10个元素降序排列,并输出结果。"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.7.1"
  },
  "toc": {
   "base_numbering": 1,
   "nav_menu": {},
   "number_sections": false,
   "sideBar": true,
   "skip_h1_title": false,
   "title_cell": "Table of Contents",
   "title_sidebar": "Contents",
   "toc_cell": false,
   "toc_position": {
    "height": "calc(100% - 180px)",
    "left": "10px",
    "top": "150px",
    "width": "165px"
   },
   "toc_section_display": true,
   "toc_window_display": false
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
